package com.thinkit.bigdata.web.dao.bus;

import com.thinkit.bigdata.core.feature.orm.mybatis.Page;
import com.thinkit.bigdata.web.model.bus.BusModel;
import com.thinkit.bigdata.web.model.bus.BusModelExample;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.thinkit.bigdata.web.model.bus.ModelQueryParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface BusModelMapper {
    int countByExample(BusModelExample example);

    int deleteByExample(BusModelExample example);

    int deleteByPrimaryKey(Long id);

    int insert(BusModel record);

    int insertSelective(BusModel record);

    List<BusModel> selectByExample(BusModelExample example);

    List<BusModel> selectByExample(Page<BusModel> page, BusModelExample example);

    BusModel selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("record") BusModel record, @Param("example") BusModelExample example);

    int updateByExample(@Param("record") BusModel record, @Param("example") BusModelExample example);

    int updateByPrimaryKeySelective(BusModel record);

    int updateByPrimaryKey(BusModel record);

    //新增方法
    List<BusModel> selectByConditionAndPagenationAndMutilTable(HashMap<String, Object> params);

    List<BusModel> selectByConditionAndPagenationAndMutilTable(Page<BusModel> page, HashMap<String, Object> params);

    List<BusModel> selectByConditionAndMutilTable(ModelQueryParam queryParam);

    List<BusModel> selectByPrimaryKeyWithCopy(List list);

    int deleteByTypeId(Long typeId);

    List<BusModel> selectByPage(Page<BusModel> page, HashMap<String, Object> params);

    List<BusModel> selectByPage(HashMap<String, Object> params);


    /**
     * 查询模型任务状态
     *
     * @param ids
     * @return
     */
    @Select("<script>"
            + "SELECT bw.id AS 'task_id' ,bw.workName AS 'task_name' ,bw.proStatus AS 'task_status', "
            + "bm.name AS 'model_name',bw.workType "
            + "FROM bus_work bw, bus_work_model wm, bus_model bm "
            + "WHERE bw.id = wm.workId AND wm.modelId = bm.id AND wm.modelId IN"
            + "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "UNION SELECT DISTINCT "
            + "bm.id AS 'task_id','模型测检' AS 'task_name',bw.proStatus AS 'task_status',bm.name AS 'model_name' ,2 workType "
            + "FROM bus_work_test bw, bus_wkt_model wm, bus_model bm "
            + "WHERE bw.id = wm.workId AND wm.modelId = bm.id AND bw.proStatus=1 AND wm.modelId IN"
            + "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>"
    )
    List<Map<String, Object>> query_modelTask_status(@Param("ids") List<Long> ids);
}